package xyz.thoughtset.viewer.apis.client.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.thoughtset.viewer.common.core.factory.AnnMgtFactory;
import xyz.thoughtset.viewer.common.show.helper.SchemaHelper;
import xyz.thoughtset.viewer.executor.core.constants.TypeConstants;

@RestController
@RequestMapping("/s/")
public class SchemaApi {
    @Autowired
    private AnnMgtFactory annMgtFactory;
    @Autowired
    private ObjectMapper objectMapper;

    @GetMapping("/edit")
    @ResponseBody
    public Object edit(@RequestParam String subject,@RequestParam(required = false) String group){
        return TypeConstants.BASE_TYPE_LIST;
    }
    @SneakyThrows
    @GetMapping("/editcur")
    @ResponseBody
    public Object editCur(@RequestParam String subject,@RequestParam(required = false) String group){
        Class subType = annMgtFactory.findTypeBySub(subject);
        return objectMapper.writeValueAsString(
                SchemaHelper.editWebSelfStruct(subType)
        );
    }


}
